<?php
	$host = "localhost";
	$port = 5432;
	$dbname = "demo";
	$user = "postgres";
	$pass = "pass";
	$thesaurus = "Culture";
	
	if (isset($_GET['query']))
	{
		if ($_GET['query'] == "assoc")
		{
			if (isset($_GET['concept']))
			{
				$db = pg_connect("host=$host port=$port dbname=$dbname user=$user password=$pass");
				// TODO : RECUPERER CONCEPTS ET NOM DES ASSOCIATIONS.
				
				$queryAssocs = pg_query($db, "SELECT * FROM GET_ASSOCIATIONS1('".$_GET['concept']."') 
								AS (concept_oid OID, association TEXT, concept TEXT, reflex BOOLEAN);");
				if(!$queryAssocs) {echo "error"; exit;}
				
				// Stocke les nom des concepts associés
				$conceptsAssocies = "";
				$associations = "";
				
				// Traiter et afficher les assocs
				for($i = 0; $i<pg_numrows($queryAssocs); $i++)
				{
					$object = pg_fetch_object($queryAssocs, $i);
					
					if($i != pg_numrows($queryAssocs) -1)
					{
						$conceptsAssocies .= $object->concept."*";
						$associations .= $object->association."*";
					}
					else
					{
						$conceptsAssocies .= $object->concept;
						$associations .= $object->association;
					}
				}
				
				// Affichage des deux chaînes séparées
				echo "$conceptsAssocies!$associations";
			}
		}
	}
?>
